var conturl = 'http://shengbb.com';

//登录页面
function login() {
	var user = $("#usertel").val();
	var password = $("#userpassword").val();
	$.ajax({
		type: "post",
		url: "/baby/sys/login",
		data: {
			username: user,
			password: password
		},
		async: true,
		dataType: 'json',
		success: function(data) {
			if(data.code == 2000) {
				console.log(data);
				window.location.href = "main.html";
			} else {
				alert(data.message);
			}
		}
	});
}

//注册页面--创建账户
function register(){
 	
	var phone =$("#phone").val();
	var name =$("#name").val();
	var pwd =$("#pwd").val();

	var password =$("#password").val();
	var pushCode =$("#pushCode").val();
	if(phone==''|| name==''|| pwd==''||password==''||pushCode==''){
		alert('信息不完整');
		return;
	}
	if(pwd!=password){
		alert("两次密码不一致");
		return;
	}
	$.ajax({  
	    url:'/baby/sys/sysAddUser',// 跳转到 action  
	    data:{
			 phonNum:phone,
			 pwd:password,
			 checkNum:pushCode,
			 name:name
	    },  
	    type:'post',  
	    cache:false,  
	    dataType:'json',  
	    success:function(data){ 
	        if(data.code =="2000" ){
	            alert(data.message);
	         //   window.location.href = "login.html"
	        }else{  
	            alert(data.message);
	        }  
	    }, error : function() {      
	    }  
		
	});
		
} 
//注册页面--获取验证码
var registertime = 60;
function getcode() {
	if(registertime == 0) {
		$("#register_code").attr("disabled", false);
		$("#register_code").html("获取验证码");
		registertime = 60;
	} else if(registertime < 60) {
		$("#register_code").attr("disabled", true);
		$("#register_code").html("重新发送(" + registertime + ")");
		registertime--;
		setTimeout(function() {
			getcode()
		}, 1000)
	} else if(registertime == 60) {
		console.log(1)
		registertime--;
		pushcode();
		getcode();
	}
}
//注册页面--发送验证码
function pushcode(){
	var phone =$("#phone").val();
	if(phone==''){
		alert('请输入一个手机号');
		return;
	}
	$.ajax({  
	    url:'/baby/sys/pushCode',// 跳转到 action  
	    data:{
			 phonNum:phone
	    },  
	    type:'post',  
	    cache:false,  
	    dataType:'json',  
	    success:function(data){ 
	    	 console.log(data);  
	        if(data.code =="2000" ){ 
	            alert(data.message);
	        }else{  
	            alert(data.message);
	        }  
	    }, error : function() {
	    	
	    }  
	});
}